<?php
class galleryDeleteAction extends sfActions
{
    public function execute($request)
    {
        $path_files = "";
    	$gallery_id = $request->getParameter('gallery_id');
        $this->forward404Unless($gallery = Doctrine_Core::getTable('VTNSgallery')->find($gallery_id), sprintf('Object gallery does not exist (%s).',$gallery_id));
        if(isset($gallery->picture) && $gallery->picture != null) {
            foreach($gallery->dimensions as $dimension) {
                $path_file = "uploads/gallery/".$dimension['name'].$gallery->picture;
                if(file_exists($path_file))
					unlink($path_file);
            }
            $path_file = "uploads/gallery/".$gallery->picture;
            if(file_exists($path_file))
				unlink($path_file);
            $gallery->delete();   
        }
       $this->redirect('gallery/galleryList?gallery_category_id='.$gallery->gallery_category_id);
    	return sfView::SUCCESS;
    }
}
?>